namespace PickGold.Charting.Design
{
    using System;
    using System.ComponentModel;
    using System.Globalization;

    internal class DataPointCustomPropertiesConverter : TypeConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if ((context != null) && (destinationType == typeof(string)))
            {
                return "";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(value, attributes, false);
            if (((context == null) || !(context.Instance is ChartElement)) || (((context.Instance as ChartElement).Chart == null) || !(context.Instance as ChartElement).Chart.IsDesignMode()))
            {
                return descriptors;
            }
            PropertyDescriptorCollection descriptors2 = new PropertyDescriptorCollection(null);
            foreach (PropertyDescriptor descriptor in descriptors)
            {
                if (descriptor.Name == "CustomAttributesEx")
                {
                    DynamicPropertyDescriptor descriptor2 = new DynamicPropertyDescriptor(descriptor, "CustomProperties");
                    descriptors2.Add(descriptor2);
                }
                else
                {
                    descriptors2.Add(descriptor);
                }
            }
            return descriptors2;
        }

        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}

